package com.wu.server.code;

import org.springframework.data.relational.core.sql.In;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * @author Wugs
 * @version 1.0
 * @date 2021/3/4 19:58
 */
@Component
public class Code {
    HashMap<Integer,String> msg = new HashMap<>();//定义消息对象
    public static final int SUCCESS =  100;//失败
    public static final int FAIL =  0;//失败
    public static final int SPIDER_TYPE = 101;//开始爬取type总类数据
    public static final int TYPE_FINISH = 102;//标签数据爬取完成

    public static final int SPIDER_GOODS = 201;//开始爬取goods数据
    public static final int GOODS_FINISH = 202;//商品数据爬取完成

    public static final int EXECUTE = 301;//解析标签数据

    public static final int TYPENUM = 401;//种类商品数目
    public static final int TYPESALES = 402;//种类销量分析
    public static final int PRICENUM = 403;//价格区间分析
    public static final int PRICESALES = 404;//价格销量分析
    public static final int TAGSALES = 405;//优惠销量分析
    public static final int SELF = 406;//自营商铺比重
    public static final int SHOPTOP = 407;//热销店铺
    public static final int GOODSTOP = 408;//商品top100


    public static final int creatFail = 501;//创建失败
    public static final int checkFail = 502;//检查失败
    public static final int PARAM_ERROR = 503;//参数错误
    public static final int updateFail = 504;// 修改失败
    public static final int deleteFail = 505;// 删除失败
    public static final int notUser = 506; // 没有这个用户

    /**
     * // TODO: 2021/3/4 s生成单例msg消息对象
     */
    private void msgInit() {
        msg.put(SUCCESS, "成功！");
        msg.put(FAIL, "未知错误！");
        msg.put(SPIDER_TYPE, "开始爬取标签数据");
        msg.put(TYPE_FINISH, "标签数据爬取完成");
        msg.put(SPIDER_GOODS, "开始爬取商品数据");
        msg.put(GOODS_FINISH, "商品数据爬取完成");
        msg.put(EXECUTE, "开始解析数据");
        msg.put(TYPENUM, "种类数目分析");
        msg.put(TYPESALES, "种类销量分析");
        msg.put(PRICENUM, "价格区间分析");
        msg.put(PRICESALES, "价格销量分析");
        msg.put(TAGSALES, "优惠销量分析");
        msg.put(SELF, "自营商品比重分析");
        msg.put(SHOPTOP, "热销店铺");
        msg.put(GOODSTOP, "热销商品");
        msg.put(creatFail, "新增失败");
        msg.put(PARAM_ERROR, "缺少参数");
        msg.put(updateFail, "更新失败");
        msg.put(deleteFail, "删除失败");
        msg.put(checkFail,"验证失败");
        msg.put(notUser,"没有这个用户");

    }
    public String getMsg(int code){
        if(msg.isEmpty()){  msgInit();  }
        return msg.get(code);
    }

    /**
     * 获取消息
     * @param { number } code
     * @return HashMap
     */
    public HashMap<String,Object> getMeta(int code,Object data){
        HashMap<String,Object> meta = new HashMap<>();
        if (data != null){
            meta.put("data",data);
        }
        meta.put("msg",getMsg(code));
        meta.put("code",code);
        return meta;
    }

}
